function xhr(obj){
	var baseUrl = 'http://192.168.134.1:5555'
	var xhr = new XMLHttpRequest()
	xhr.open(obj.methods||'get',baseUrl+obj.url)
	if(obj.header){
		for(var key in obj.header){
			xhr.setRequestHeader(key,obj.header[key])
		}
	}else{
		xhr.setRequestHeader('Content-Type','application/json')
		xhr.setRequestHeader('token',splitToken('token'))
	}
	xhr.send(obj.data||null)
	xhr.onreadystatechange =function(){
		if(xhr.readyState==4&&xhr.status == 200){
			obj.success && obj.success(JSON.parse(xhr.response))
		}
	}
}
/**
 * {type} success  error  
 * {msg}  信息提示 
 */
function popupMsg(type,msg){
	swal({
		icon: type||'success',
		text: msg||'成功',
	});
}

// 截取url token
function splitToken(key){
	var result = null
	try {
		var url = location.href.split('?')[1].split('&')
		for(var i=0;i<url.length;i++){
			var item = url[i].split('=')
			if(item[0]===key){
				result = item[1]
			}
		}
	} catch (error) {
		result = false
	}
	
	return result
}